package com.lbs.utils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;


/**
 * @author Administrator
 * @date 2021/5/31 19:22
 * @description
 **/
public class FileUploadUtils {

    public static String fileUpload(HttpServletRequest request) throws IOException, ServletException {
        Part file = request.getPart("file");
        String fileName = file.getSubmittedFileName();
        fileName = System.currentTimeMillis() + fileName.substring(fileName.lastIndexOf("."));
        File filePath = new File("F:\\IdeaProjects\\中公-JavaWeb\\upload\\");
        if (!filePath.exists()){
            filePath.mkdirs();
        }
        file.write(filePath+"/"+fileName);
        return fileName;
    }

}
